/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package game.scene.map;
import starruby.Texture;
import java.util.Enumeration;
import dgo.tilemap.*;
import dgo.MyLib;
import game.Config;

/**
 *
 * @author Daigo
 */
public class View {
  public void renderClockControl(Model model, Texture s){
    if(model.globalModel.variables[12] >= 0){
      s.renderTexture(model.textureManager.getTexture("system/clock/cancel"), 165, 220);
      
      String t = "";
      int v = model.player().screenX - 8;
      if(v > 208){v -= 8;}
      if(v <= 0){v += 24;}
      
      if(model.globalModel.switches[1]){
        s.renderTexture(model.textureManager.getTexture("system/clock/left_stop"), v- 8, model.player().screenY - 8);
      }else{
        t = model.globalModel.variables[12] == 0 ? "_down" : "";
        s.renderTexture(model.textureManager.getTexture("system/clock/left" + t), v - 8, model.player().screenY - 8);
      }
      
      t = model.globalModel.variables[12] == 1 ? "_down" : "";
      s.renderTexture(model.textureManager.getTexture("system/clock/stop" + t), v + 8, model.player().screenY - 8);

      if(model.globalModel.switches[2]){
        s.renderTexture(model.textureManager.getTexture("system/clock/right_stop"), v + 24, model.player().screenY - 8);
      }else{
        t = model.globalModel.variables[12] == 2 ? "_down" : "";
        s.renderTexture(model.textureManager.getTexture("system/clock/right" + t), v + 24, model.player().screenY - 8);
      }
    }else{
      if(!model.player().pause){
        s.renderTexture(model.textureManager.getTexture("system/clock/use_clock"), 165, 220);
      }
    }
  }

  public void renderCharacters(Model model, Texture s, int layerNo){
    Enumeration e;
    MyLib.sortCharacters(model.characters);
    
    e =  model.characters.elements();
    while(e.hasMoreElements()){
      MapCharacter c = (MapCharacter)e.nextElement();
      if(c.layer == layerNo) c.render(s, -model.map.baseX, -model.map.baseY);
    }
  }
  
  private void changeHue(Model model, Texture s){
    s. changeHue(model.globalModel.screenRed, model.globalModel.screenGreen, model.globalModel.screenBlue);
  }

  public void update(Model model, Texture s){
    model.map.renderPanorama(s);
    model.map.render(s,  0);
    renderCharacters(model, s, 0);
    renderCharacters(model, s, 1);
    model.map.render(s,  1);
    renderCharacters(model, s, 2);
    changeHue(model, s);
    renderClockControl(model, s);
    
    model.windowManager.render(s, 0, Config.MAP_DELTA_Y);
  }
}
